From: Jim Porter Date: Mon, 21 Jul 2025 04:17:05 +0000 (-0700) Subject: Fix Eshell call to 'string-suffix-p' when checking for trailing newline X-Git-Tag: archive/raspbian/1%30.2+1-2+rpi1^2~2^2~24^2~21 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22Program/%22http:/www.example.com/cgi/%22https:/%22Program?a=commitdiff_plain;h=dd29b0ab66d63b3b8e890c8de8f8e5c3fb44217a;p=emacs.git Fix Eshell call to 'string-suffix-p' when checking for trailing newline * lisp/eshell/esh-io.el (eshell--output-maybe-n): Fix call. * test/lisp/eshell/esh-io-tests.el (esh-io-test/output-newline/add-newline) (esh-io-test/output-newline/no-newline) (esh-io-test/output-newline/no-extra-newline): New tests (bug#79063). --- diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el index ff275560a04..1b474d988a7 100644 --- a/lisp/eshell/esh-io.el +++ b/lisp/eshell/esh-io.el @@ -569,7 +569,7 @@ ends in a newline." (eshell-output-object object handle) (when (and eshell-ensure-newline-p (not (and (stringp object) - (string-suffix-p object "\n")))) + (string-suffix-p "\n" object)))) (eshell-maybe-output-newline handle))) (defsubst eshell-print-maybe-n (object) diff --git a/test/lisp/eshell/esh-io-tests.el b/test/lisp/eshell/esh-io-tests.el index 0b25ad812fa..e6bc5c9809c 100644 --- a/test/lisp/eshell/esh-io-tests.el +++ b/test/lisp/eshell/esh-io-tests.el @@ -41,6 +41,28 @@ ;;; Tests: + +;; Newlines + +(ert-deftest esh-io-test/output-newline/add-newline () + "Ensure we add a newline when writing a string to stdout." + (with-temp-eshell + (eshell-match-command-output "(concat \"hello\")" "\\`hello\n\\'"))) + +(ert-deftest esh-io-test/output-newline/no-newline () + "Ensure we don't add a newline when writing a string to a buffer." + (eshell-with-temp-buffer bufname "" + (with-temp-eshell + (eshell-match-command-output + (format "(concat \"hello\") > #<%s>" bufname) + "\\`\\'")) + (should (equal (buffer-string) "hello")))) + +(ert-deftest esh-io-test/output-newline/no-extra-newline () + "Ensure we don't add an extra newline when writing to stdout." + (with-temp-eshell + (eshell-match-command-output "(concat \"hello\n\")" "\\`hello\n\\'"))) + ;; Basic redirection